﻿#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using MediaWiki.Office.Packaging;

namespace MediaWiki.Office.Model
{
  public class DocumentContent : Content
  {
    public DocumentContent(Content parent)
      : base(parent)
    {
    }

    public static DocumentContent Create(Content parent, XElement contentElement)
    {
      switch (contentElement.Name.LocalName)
      {
        case "p":
          return new Paragraph(parent, contentElement);
        case "tbl":
          return new Table(parent, contentElement);
        case "sdt":
          return new BlockStructuredTag(parent, contentElement);
        default:
#if STRICT
          throw new ArgumentOutOfRangeException(contentElement.Name.LocalName);
#else
          return null;
#endif
      }
    }

    public static List<DocumentContent> Create(Content parent, IEnumerable<XElement> elements)
    {
      if (elements == null)
        throw new ArgumentNullException("elements");

      var content = from e in elements
                    where e.Name == Paragraph.Name || e.Name == Table.Name || e.Name == BlockStructuredTag.Name
                    select DocumentContent.Create(parent, e);

      return content.ToList();
    }
  }
}